import React, { Component } from 'react'
import Img from "@/assets/images/home/subject.png"
import "./Fast.less"
import { FastAnswerApi } from "@/request/api.js"
export default class Fast extends Component {
    state = {
        showLoading: true,
        // 学科列表
        records: []
    }




    render() {
        return (
            <div className="fast_page">
                <ul className="list">
                    {
                        this.state.records.map((item, index) =>
                            <li key={index}>
                                <img src={Img} alt="" />
                                <section>
                                    <h3>{item.info}</h3>
                                </section>
                                <div className="r">
                                    刷题
                                </div>
                            </li>
                        )
                    }
                </ul>
            </div>
        )
    }
    async componentDidMount() {
        let token = localStorage.getItem("x-auth-token")
        if (token) {
            let res = await FastAnswerApi()
            this.setState({
                showLoading: false
            })
            console.log(res);
            // 针对登录失效的问题，跳转到登录页面
            if (res.response && res.response.data.errCode === 1002) {
                this.props.history.push("/login")
                return
            }




            //做请求
            let { records } = res.data
            this.setState({
                records: records
            })


        } else {
            this.setState({
                showLoading: true
            })
            setTimeout(() => {
                this.setState({
                    showLoading: false
                })
                this.props.history.push("/login")
            }, 500)


        }
    }
}
